package com.woniuxy.food.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodskuclient.FoodSkuManageClient;
import com.woniuxy.food.client.param.InsertFoodSkuParam;
import com.woniuxy.food.client.param.UpdateFoodSkuParam;
import com.woniuxy.food.service.FoodSkuService;
import com.woniuxy.food.service.serviceparam.InsertFoodSkuServiceParam;
import com.woniuxy.food.service.serviceparam.UpdateFoodSkuServiceParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import java.math.BigDecimal;

@RestController
public class FoodSkuManageClientApiImpl implements FoodSkuManageClient {
    @Autowired
    private FoodSkuService foodSkuService;
    @Override
    @Log("添加菜品sku")
    public Result insertFoodSku(InsertFoodSkuParam param) {
        InsertFoodSkuServiceParam insertFoodSkuServiceParam = BeanUtil.toBean(param, InsertFoodSkuServiceParam.class);
        foodSkuService.insertFoodSku(insertFoodSkuServiceParam);
        return Result.success();
    }

    @Override
    @Log("菜品sku上下架")
    public Result updateFoodSkuStateByIds(Integer storeId,Integer[] ids,String skuState) {
        foodSkuService.updateFoodSkuStateByIds(storeId,ids,skuState);
        return Result.success();
    }

    @Override
    @Log("根据ID修改菜品sku")
    public Result updateFoodSku(UpdateFoodSkuParam param) {
        UpdateFoodSkuServiceParam updateFoodSkuServiceParam = BeanUtil.toBean(param, UpdateFoodSkuServiceParam.class);
        foodSkuService.updateFoodSku(updateFoodSkuServiceParam);
        return Result.success();
    }

    @Override
    @Log("修改销量")
    public Result updateFoodSkuSalesCount(Integer storeId,Integer skuId, Long salesCount) {
        foodSkuService.updateFoodSkuSalesCount(storeId,skuId,salesCount);
        return Result.success();
    }

    @Override
    @Log("修改折扣价")
    public Result updateFoodSkuDiscountPrice(Integer storeId,Integer skuId, BigDecimal discountPrice) {
        foodSkuService.updateFoodSkuDiscountPrice(storeId,skuId,discountPrice);
        return Result.success();
    }

    @Override
    @Log("删除sku")
    public Result deleteFoodSkuByIds(Integer storeId,Integer[] ids) {
        foodSkuService.deleteFoodSkuByIds(storeId,ids);
        return Result.success();
    }
}
